<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户开票申请财务列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox" id="searchPrjNmId">
                <div class="label">申请时间</div>
                <div class="field">
                    <input name=applyTm id="applyTm" type="text" class="ui-datepicker" readonly="readonly" value="">
                </div>
            </div>
            <div class="fieldBox" id="searchCstMgrNmId">
                <div class="label">申请人</div>
                <div class="field">
                    <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" id="searchRcverNmId">
                <div class="label">收件人</div>
                <div class="field">
                    <input name="rcverNm" id="rcverNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <div class="fieldBox" id="searchCstNmId">
                <div class="label">客户名称</div>
                <div class="field">
                    <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" id="searchPaySchNoId">
                <div class="label">支付表号</div>
                <div class="field">
                    <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" id="searchInvoiceCode">
                <div class="label">发票代码</div>
                <div class="field">
                    <input name="invoiceCode" id="invoiceCode" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" id="searchBillNo">
                <div class="label">票据号</div>
                <div class="field">
                    <input name="billNo" id="billNo" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
		        </div>
	        </div>
    </form>
</div>
<!-- 开票申请列表 -->
<div id="invoiceApplyGrid" class="sq-grid"></div> 
</div>

<script type="text/javascript">
    var grid = null, menu = null;
    $(function () {
        grid = $("#invoiceApplyGrid").ligerGrid({
            url: '<%=path%>/invoice/prjbillapply/initFinanceList.do',
            method: 'get',
            columns: [
                {display: '申请ID', name: 'id', width: 140, align: 'center', enabledSort: false},
                {
                    display: '申请时间', name: 'applyTm', width: 180,
                    render: function (rowdata, rowindex, value, column) {
                        var time = DateUtils.formatDateToString(value, DateUtils.YYYY_MM_DDHHMMSS);
                        var h = '';
                        h = '<a  href="javascript:showDetail(';
                        h += "'" + rowdata.id + "'";
                        h+=",'"+rowdata.billWayCd+"'";
                        h += ')">' + time + '</a>'
                        return h;
                    }, align: 'center', enabledSort: false
                },
                {display: '申请人', name: 'cstMgrNm', width: 80, align: 'center', enabledSort: false},
                {display: '客户名称', name: 'cstNm', width: 120, align: 'center', enabledSort: false},
                {display: '证件号码', name: 'identify', width: 200, align: 'center', enabledSort: false},
                {display: '开具方式', name: 'billWayCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '开票状态', name: 'audStsCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '流程编号', name: 'pno', width: 150, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value){
                        var h = '';
                        h='<a  href="javascript:commShowFlow(';
                        h+="'"+rowdata.pinstId+"'";
                        h+=",'"+rowdata.audStsCd+"'";
                        h+=",'"+rowdata.id+"'";
                        h+=')">'+UIUtils.showColumnTip(value)+'</a>'
                        return h;
                    }
                },
                getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,

            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function ()
            {
                var grid = this;
                grid.collapsedRows = [];
            },
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
        });
        
        initForm();
    });

    // 显示流程
    function commShowFlow(_pInstId, _audStsCd, _businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/invoice/prjbillfeer/toAuditingDetailPage.do?id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //展示详情
    function showDetail(_id, flag) {
        var url;
        // flag = "2";
        if ("1" == flag) {
            // 电子详情
            url = '<%=path%>/invoice/electron/toDetailPage.do';
        } else if ("2" == flag) {
            // 纸质详情
            url = '<%=path%>/invoice/prjbillfeer/toAuditingDetailPage.do';
        }
        //弹出一个窗口
        $.ligerDialog.SQopen({
            title: '申请详细',
            width: 1000,
            height: 550,
            url: url,
            urlParms: {id: _id},
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [
                {
                    text: "关闭", onclick: function (item, Dialog) {
                        if (Dialog.onCancel) {
                            Dialog.onCancel();
                        }
                    }
                }
            ]
        });
    }

    //初始化Form
    function initForm(){
		ligerPersonForm = $("#div_invoice_apply_valid_form").ligerForm({
         	 validate: true
  		});
    }

    //逾期明细列表
    function showDetail_grid(row, detailPanel, callback){
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            // url: '<%=path%>/invoice/prjbillfeer/initList.do?applyId='+row.id,
            url: '<%=path%>/invoice/prjbillbscinfo/initInvoiceManageList.do?applyId='+row.id,
            method: 'get',
            columns: [{display: '业务模式', name: 'bizTypCdNm', width: 150, align: 'center'},
                {display: '合同号',name: 'lsCntNo',width: 180,align:'center'},
                {display: '开票金额(元)',name: 'billAmt', width: 80,align:'right',
	                render:function(rowdata,index,value){
	                    return '&yen;' + FormatMoney(rowdata.billAmt/100);
	                }
	            },
                {display: '发票代码', name: 'invoiceCode', width: 120, align: 'center', enabledSort: false},
                {display: '票据号', name: 'billNo', width: 100, align: 'center', enabledSort: false},
                {display: '票据类型', name: 'billTypCdNm', width: 150, align: 'center'},
                {display: '票据状态', name: 'billStsCdNm', width: 100, align: 'center'},
                {
                    display: '实收金额', name: 'billAmt', width: 100, align: 'center', enabledSort: false, render:
                        function (rowdata) {
                            return rowdata.billAmt / 100;
                        }
                },
                {
                    display: '开票日期', name: 'makeDate', width: 110, align: 'center', enabledSort: false, render:
                        function (rowdata) {
                            return renderDate(rowdata.makeDate);
                        }
                },
                {
                    display: '发票流水号', name: 'serialNo', width: 180, align: 'center', enabledSort: false
                },
                getGridOperColumnContent4Invoice(row.billWayCd)
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers:true,  //显示序号
            allowUnSelectRow:true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    //获取Grid操作列内容
    function getGridOperColumnContent4Invoice(billWayCd){
        var data = {
            display: '操作',
            isSort: false,
            align: 'left',
            width: 500,
            render: function (rowdata, rowindex, value) {
                var h;
                if ("2" == billWayCd) {
                    if ("1" == rowdata.billStsCd) {
                        h = '<a  class="sq-button-hasicon" alt="作废" href="javascript:invalidInvoice(';
                        h += "'" + rowdata.id + "'";
                        h += ",'" + rowdata.applyId + "'";
                        h += ")\"><i class=\"sqBtnIco_7\"></i>作废</a>";
                    }
                    // h += '<a  class="sq-button-hasicon" alt="冲红" href="javascript:revertInvoice(';
                    // h += "'" + rowdata.id + "'";
                    // h += ",'" + rowdata.billWayCd + "'";
                    // h += ")\"><i class=\"sqBtnIco_19\"></i>冲红</a>";
                    if ("4" != rowdata.billTypCd) {
                        if (h) {
                            h += '<a  class="sq-button-hasicon" alt="打印" href="javascript:printInvoice(';
                        } else {
                            h = '<a  class="sq-button-hasicon" alt="打印" href="javascript:printInvoice(';
                        }
                        h += "'" + rowdata.id + "'";
                        h += ",'" + rowdata.applyId + "'";
                        h += ")\"><i class=\"sqBtnIco_8\"></i>打印</a>";
                    }

                } else if ("1" == billWayCd) {
                    // h = '<a  class="sq-button-hasicon" alt="冲红" href="javascript:revertInvoice(';
                    // h += "'" + rowdata.id + "'";
                    // h += ",'" + rowdata.billWayCd + "'";
                    // h += ")\"><i class=\"sqBtnIco_19\"></i>冲红</a>"

                }
                return h;
            }
        }
        return data;
    }

    function renderDate(value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

  	//查看支付表详情
    function detailBtn(id,paySchId){
    	var editFlag = true;
    	Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toPrjPrdPaySchMDetailPageBySchId.do?paySchId='+paySchId);
     }
    //获取Grid操作列内容
    function getGridOperColumnContent(){
        var data = {
            display: '操作',
            isSort: false,
            align: 'left',
            width: 500,
            render: function (rowdata, rowindex, value) {
                var h;
                if ("2" == rowdata.billWayCd) {
                    h = '<a  class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
                    h += "'" + rowdata.id + "'";
                    h += ")\"><i class=\"sqBtnIco_4\"></i>" + LogUtils.LOG_CMM_GRID_BTN_MODIFY + "</a>"
                } else if ("1" == rowdata.billWayCd) {
                    // h = '<a  class="sq-button-hasicon" alt="冲红" href="javascript:revertInvoice(';
                    // h += "'" + rowdata.id + "'";
                    // h += ",'" + rowdata.billWayCd + "'";
                    // h += ")\"><i class=\"sqBtnIco_19\"></i>冲红</a>"

                }
                return h;
            }
        }
        return data;
    }

    // 作废
    function invalidInvoice(_id, applyId) {
        var params = "?id=" + _id + "&applyId=" + applyId + "&flag=3";
        Add_navTab('tab_invoice_invalid_apply_' + _id, '作废发票', '<%=path%>/invoice/prjbillfeer/toAuditingPage.do' + params, function () {
            grid.reload();
        });
    }

    // 冲红
    function revertInvoice(_id, billWayCd) {
        var params = "?id=" + _id + "&flag=4" + "&billWayCd=" + billWayCd;
        Add_navTab('tab_invoice_revert_apply_' + _id, '冲红发票', '<%=path%>/invoice/prjbillfeer/toAuditingPage.do' + params, function () {
            grid.reload();
        });
    }
    
    // 打印
    function printInvoice(_id,  applyId) {
        var params = "?id=" + _id + "&applyId=" + applyId + "&flag=2";
        Add_navTab('tab_invoice_print_apply_' + _id, '打印发票', '<%=path%>/invoice/prjbillfeer/toAuditingPage.do' + params, function () {
            grid.reload();
        });
    }

    // 修改
    function modifyRow(_id){
        var params = "?id="+_id + "&mdf=1";
        Add_navTab('tab_invoice_modify_apply_'+_id,'修改发票','<%=path%>/invoice/prjbillfeer/toAuditingPage.do'+params,function(){
            grid.reload();
        });
    }

</script>

</body>
</html>